package com.springcloud.controller;

import com.netflix.discovery.converters.Auto;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.springcloud.entities.CommonResult;
import com.springcloud.entities.Payment;
import com.springcloud.fegin.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("consumer/payment/info")
    public CommonResult<Payment> getPayment(@RequestBody Payment payment){
        return orderService.getPayment(payment);
    }

    @GetMapping("consumer/payment/{id}")
    @HystrixCommand(fallbackMethod = "getPaymentHystrix")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id){
        int i = 1/0;
        return orderService.getPayment(id);
    }

    public CommonResult<Payment> getPaymentHystrix(@PathVariable("id") Long id){
        Payment payment = new Payment();
        payment.setId(id);
        payment.setSerial("异常");
        return new CommonResult(200,"成功",payment);
    }

}
